package com.acwing.partition9;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/5/4 9:03
 */
public class AC831KMP字符串 {

    private static final int N = 100010, M = 1000010;
    private static char[] s = new char[M], p = new char[N];
    private static int[] next = new int[N];
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        m = Integer.parseInt(reader.readLine());
        String ss = reader.readLine();
        for (int i = 1; i <= m; i++) p[i] = ss.charAt(i - 1);
        n = Integer.parseInt(reader.readLine());
        ss = reader.readLine();
        for (int i = 1; i <= n; i++) s[i] = ss.charAt(i - 1);

        for (int i = 2, j = 0; i <= m; i++) {
            while (j > 0 && p[i] != p[j + 1]) j = next[j];
            if (p[i] == p[j + 1]) j++;
            next[i] = j;
        }
        for (int i = 1, j = 0; i <= n; i++) {
            while (j > 0 && s[i] != p[j + 1]) j = next[j];
            if (s[i] == p[j + 1]) j++;
            if (j == m) {
                writer.write((i - m) + " ");
                j = next[j];
            }
        }
        writer.flush();
        writer.flush();
    }
}
